package com.mt.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author Wang
 * @Description 订单状态枚举类
 * @date 2021/1/4-23:51
 */
@Getter
public enum OrderStatus {
    NOT_PAY(0, "未支付"),
    PAYED(1, "已支付"),
    CANCELING(2,"退款中"),
    CANCEL(3,"已取消"),
    FINISH(4,"已完成");

    @EnumValue
    private Integer code;
    @JsonValue
    private String msg;

    OrderStatus(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static int TypeCode(OrderStatus listType) {
        for (OrderStatus pay : OrderStatus.values()){
            if (pay.getMsg()==listType.getMsg()) {
                return pay.getCode();
            }
        }
        return -1;
    }

    public static String TypeName(OrderStatus listType) {
        for (OrderStatus pay : OrderStatus.values()){
            if (pay.getCode().equals(listType.getCode())) {
                return pay.getMsg();
            }
        }
        return null;
    }

    public static OrderStatus getOrderStatus(Integer code) {
        for (OrderStatus pay : OrderStatus.values()){
            if (pay.getCode().equals(code)) {
                return pay;
            }
        }
        return null;
    }
}
